home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-22 | 4.5 KB | 210 lines | [TEXT/KAHL] |
- // ResEdit Extensions
- // Copyright 1995#include <A4Stuff.h>
- #include "ShowINIT.h"
- #include <Folders.h>
- #include <Script.h>
- #include <Aliases.h>
- #include <Processes.h>
- #include <GestaltEqu.h>
- #include <Traps.h>
-
- #define kGoodIcon 128
- #define kBadIcon 129
-
- #define kMaxRecursion 10
- #define kFolderName "\pMore ResEdit Preferences"
-
- long addrStorage;
-
- void asm patchEntry (void);
- OSErr getMyPrefsFolder (FSSpec *myPrefs);
- void myPatch (Str255 fileName);
- void main (void);
-
- // Open all resource files in the folder
- // Open sub-folders and aliases to sub folders
-
- static
- void openAllInFolder (FSSpec *folder, short level)
-
- {
- CInfoPBRec pBlock;
- OSErr error;
- long dirID;
- Str63 name;
- FSSpec spec;
- Boolean wasAliased, isFolder;
-
- if (level >= kMaxRecursion)
- return;
-
- pBlock.hFileInfo.ioVRefNum = folder -> vRefNum;
- pBlock.hFileInfo.ioFDirIndex = 0;
- pBlock.hFileInfo.ioNamePtr = folder -> name;
- pBlock.hFileInfo.ioDirID = folder -> parID;
-
- error = PBGetCatInfoSync (&pBlock);
-
- if (error)
- return;
-
- dirID = pBlock.hFileInfo.ioDirID;
- pBlock.hFileInfo.ioFDirIndex = 1;
- pBlock.hFileInfo.ioNamePtr = name;
-
- while (!error) {
-
- name [0] = '\0';
-
- pBlock.hFileInfo.ioDirID = dirID;
- error = PBGetCatInfoSync (&pBlock);
-
- if (!error) {
-
- FSMakeFSSpec (pBlock.hFileInfo.ioVRefNum, dirID, name, &spec);
-
- if (pBlock.hFileInfo.ioFlAttrib & 16)
- isFolder = true;
- else
- error = ResolveAliasFile (&spec, true, &isFolder, &wasAliased);
-
- if (error == noErr) {
- if (isFolder)
- openAllInFolder (&spec, level + 1);
- else
- FSpOpenResFile (&spec, fsRdPerm);
- }
- }
- ++ pBlock.hFileInfo.ioFDirIndex;
- }
- }
-
-
- OSErr getMyPrefsFolder (FSSpec *myPrefs)
-
- {
- OSErr error;
- long newDirID;
- long prefsDir;
- short prefsVol;
- Boolean wasAliased, isFolder;
-
- error = FindFolder (kOnSystemDisk, kPreferencesFolderType, true, &prefsVol,
- &prefsDir);
-
- if (error)
- return (error);
-
- error = FSMakeFSSpec (prefsVol, prefsDir, kFolderName, myPrefs);
-
- if (error) { // Our prefs folder does not exist.
-
- error = FSpDirCreate (myPrefs, smRoman, &newDirID);
-
- if (error)
- return (error);
-
- error = FSMakeFSSpec (prefsVol, prefsDir, kFolderName, myPrefs);
-
- return (error);
- }
-
- error = ResolveAliasFile (myPrefs, true, &isFolder, &wasAliased);
- if (isFolder == false) // we only want folders!
- error = fnfErr;
-
- return (error);
- }
-
- void myPatch (Str255 fileName)
-
- {
- OSErr error;
- FSSpec mySpec;
- ProcessInfoRec pInfo;
- ProcessSerialNumber psn;
- static Boolean blockRecursion = false;
- long oldA4 = SetCurrentA4 ();
-
- if (blockRecursion) { // Don't open any files, we've already taken care of it
- SetA4 (oldA4);
- return;
- } else
- blockRecursion = true; // Prevent recursive calls to HOpenResFile
-
- // Are we opening the ResEdit Prefs file?
- if (!EqualString ("\pResEdit Preferences", fileName, true, true))
- goto Exit;
-
- // And is this ResEdit?
- GetCurrentProcess (&psn);
- pInfo.processInfoLength = sizeof (pInfo);
- pInfo.processName = nil;
- pInfo.processAppSpec = nil;
- GetProcessInformation (&psn, &pInfo);
-
- if (pInfo.processSignature != 'RSED') // Not ResEdit, bail out
- goto Exit;
-
- // Get FSSpec to the "More Preferences" folder
- error = getMyPrefsFolder (&mySpec);
- if (!error)
- openAllInFolder (&mySpec, 0); // Open prefs files contained
-
- Exit:
-
- blockRecursion = false; // we're done
- SetA4 (oldA4);
-
- return;
- }
-
- void asm patchEntry (void)
- {
- move.l 6(sp), -(sp) // re-push file name parameter
- jsr myPatch // call myPatch
- addq.l #4, sp // pop parameter
- clr.l -(sp) // reserve four bytes
- movem.l a0-a1/d0-d2/a4, -(sp) // preserve volatile regs
- jsr SetCurrentA4 // setup A4 world
- move.l addrStorage, 0x18(sp) // put ROM address in previously reserved stack space
- movem.l (sp)+, a0-a1/d0-d2/a4 // restore regs (a4 included)
- rts // jump to ROM by "returning" to the ROM address
- }
-
- void main (void)
- {
- long oldA4 = SetCurrentA4 ();
- Handle myself;
- long response;
- Boolean ok = false;
- FSSpec spec;
-
- myself = Get1IndResource ('INIT', 1);
- if (!myself)
- goto Exit;
-
- if (Button ())
- goto Exit;
-
- Gestalt (gestaltSystemVersion, &response);
- if (response < 0x00000700)
- goto Exit;
-
- ok = true;
- DetachResource (myself);
-
- addrStorage = (long) GetToolTrapAddress (0xA81A);
- SetToolTrapAddress ((UniversalProcPtr) patchEntry, 0xA81A);
-
- getMyPrefsFolder (&spec); // create the prefs folder if need be
-
- Exit:
-
- if (ok)
- ShowInit (kGoodIcon, kStandardDisplacemet);
- else
- ShowInit (kBadIcon, kStandardDisplacemet);
-
- SetA4 (oldA4);
- }